<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../js/vue.js"></script>
	</head>
	<body>
		<div id="root">
			<div>
				firstname：{{firstname}}
			</div>
			<div>
				lastname：{{lastname}}
			</div>
			<div>
				fullname：{{joinName}}
			</div>
		</div>
		
		<script type="text/javascript">
			const vm = new Vue({
				el: '#root',
				data: {
					firstname: '',
					lastname: ''
				},
				computed: {
					// 计算 firstname + ' ' + lastname
					joinName: {
						get: function() {
							return this.firstname + ' ' + this.lastname
						},
						set: function(newVal) {
							var arr = newVal.split(' ')
							this.firstname = arr[0]
							this.lastname = arr[1]
						}
					}
				}
			})
		</script>
	</body>
</html>